// 接口统一管理
import req from './req'
import reqMock from './reqMock'

// 三级联动接口 /product/getBaseCategoryList get
export const reqCategoryList = () => {
  return req({
    url:'http://gmall-h5-api.atguigu.cn/api/product/getBaseCategoryList',
    method: 'GET'
  })
}

// 获取 banner 轮播图
export const reqGetBannerList = () => {
  return reqMock.get('/banner')
}
// 获取 floor 轮播图
export const reqGetFloor = () => reqMock.get('/floor')

// 获取 SearchList 数据
export const reqGetSearchList = (params) => {
  return req({
            url: 'http://gmall-h5-api.atguigu.cn/api/list',
            method: "post",
            data: params
          })
}

// 获取 search 中 goodList 数据  接口：/api/item/{ skuId }
export const reqGoodInfo = (skuId) =>  req.get(`http://gmall-h5-api.atguigu.cn/api/item/${ skuId }`)

// 获取 detail 中购物车数据 接口：/api/cart/addToCart/{ skuId }/{ skuNum }
export const reqAddOrUpdateShopCart = (skuId,skuNum) => req.post(`http://gmall-h5-api.atguigu.cn/api/cart/addToCart/${ skuId }/${ skuNum }`)

// 获取 shopCart 中购物车数据 接口：/api/cart/cartList
export const reqCartList = () => req.get('http://gmall-h5-api.atguigu.cn/api/cart/cartList')

// shopCart 中复选框 接口：/api/cart/checkCart/{skuID}/{isChecked}
export const reqCheckCart = (skuID,isChecked) => req.get(`http://gmall-h5-api.atguigu.cn/api/cart/checkCart/${skuID}/${isChecked}`)

// 删除购物车 接口：/api/cart/deleteCart/{skuId}
export const reqDeleteCart = (skuId) => {
  return req({
    url:`http://gmall-h5-api.atguigu.cn/api/cart/deleteCart/${skuId}`,
    method: 'delete'
  })
}




// 登录与注册
// 获取验证码 接口：/api/user/passport/sendCode/{phone}
export const reqUserCode = (phone) => req.get(`http://gmall-h5-api.atguigu.cn/api/user/passport/sendCode/${phone}`)

// 获取注册用户信息 接口：/api/user/passport/register
export const reqUserRegisterInfo = (data) => req.post('http://gmall-h5-api.atguigu.cn/api/user/passport/register',data)

// 获取登录用户信息 接口：/api/user/passport/login
export const reqUserLogin = (data) => req.post('http://gmall-h5-api.atguigu.cn/api/user/passport/login',data)

// 获取用户信息【需要带着用户的token向服务器要用户信息】 接口：/api/user/passport/auth/getUserInfo
export const reqUserInfo = () => req.get('http://gmall-h5-api.atguigu.cn/api/user/passport/auth/getUserInfo')

// 退出登录 接口：/api/user/passport/logout
export const reqLoginOut = () => req.get('http://gmall-h5-api.atguigu.cn/api/user/passport/logout')





// 结算界面
// 获取用户地址 接口：/api/user/userAddress/auth/findUserAddressList
export const reqAddressInfo = () => req.get('http://gmall-h5-api.atguigu.cn/api/user/userAddress/auth/findUserAddressList')

// 获取用户商品信息 接口：/api/order/auth/trade
export const reqShopInfo = () => req.get('http://gmall-h5-api.atguigu.cn/api/order/auth/trade')




// 提交订单 接口：/api/order/auth/submitOrder?tradeNo={tradeNo}
export const reqSubmitOrder = (tradeNo,data) => req.post(`http://gmall-h5-api.atguigu.cn/api/order/auth/submitOrder?tradeNo=${tradeNo}`,data)

// 获取订单支付信息 接口：/api/payment/weixin/createNative/{orderId}
export const reqOrderPay = (orderId) => req.get(`http://gmall-h5-api.atguigu.cn/api/payment/weixin/createNative/${orderId}`)

// 支付订单状态 接口：/api/payment/weixin/queryPayStatus/{orderId}
export const reqPayCode = (orderId) => req.get(`http://gmall-h5-api.atguigu.cn/api/payment/weixin/queryPayStatus/${orderId}`)

// 获取我的订单 接口：/api/order/auth/{page}/{limit}
export const reqMyOrder = (page,limit) => req.get(`http://gmall-h5-api.atguigu.cn/api/order/auth/${page}/${limit}`)

/*
  mock的数据 
*/
export const reqMockUserDefaultAddressInfo = () => reqMock.get('/user/addressInfo')
